package com.wonders.module.auth.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.wonders.framework.dao.impl.BaseDaoImpl;
import com.wonders.framework.entity.vo.Parameter;
import com.wonders.module.auth.dao.UserRoleDao;

/**
 * 用户角色信息数据层实现
 * 
 * @author WuBin
 * 
 */
@Repository
public class UserRoleDaoImpl extends BaseDaoImpl implements UserRoleDao {

	public void removeRoleUser(Long roleId, List<Long> keys) {
		String hql = "delete from UserRole ur where ur.roleId = :roleId and ur.userId in (:keys)";
		List<Parameter> args = new ArrayList<Parameter>();
		args.add(new Parameter("roleId", roleId));
		args.add(new Parameter("keys", keys));
		super.excuteHql(hql, args);
	}

	public void removeUserRole(Long userId, List<Long> keys) {
		String hql = "delete from UserRole ur where ur.userId = :userId and ur.roleId in (:keys)";
		List<Parameter> args = new ArrayList<Parameter>();
		args.add(new Parameter("userId", userId));
		args.add(new Parameter("keys", keys));
		super.excuteHql(hql, args);
	}

	public void removeUserRoleByUsers(List<Long> users) {
		String hql = "delete from UserRole ur where ur.userId in (:users)";
		List<Parameter> args = new ArrayList<Parameter>();
		args.add(new Parameter("users", users));
		super.excuteHql(hql, args);
	}

	public void removeUserRoleByRoles(List<Long> roles) {
		String hql = "delete from UserRole ur where ur.roleId in (:roles)";
		List<Parameter> args = new ArrayList<Parameter>();
		args.add(new Parameter("roles", roles));
		super.excuteHql(hql, args);
	}

}
